package mvc.views.mediators
{
	import alternativa.gui.data.DataProvider;
	import alternativa.gui.layout.LayoutManager;
	
	import globals.Global;
	
	import mvc.Notifications;
	import mvc.views.AppMainView;
	import mvc.views.frames.Frame;
	import mvc.views.frames.FrameAccessList;
	import mvc.views.frames.FrameLogin;
	import mvc.views.layers.BackgroundLayer;
	import mvc.views.layers.UILayer;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import utils.UtilsAnimation;
	
	import xl.utils.Tracker;
	
	public class MediatorUILayer extends Mediator implements IMediator
	{
		public static const NAME:String = "MediatorUILayer";
		
		private var uiLayer:UILayer;
		public function MediatorUILayer(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
			uiLayer = viewComponent as UILayer;
		}
		
		override public function listNotificationInterests():Array
		{
			// TODO Auto Generated method stub
			return [
				Notifications.MEDIATOR_SWITCH_SCENE,
				Notifications.MEDIATOR_SWITCH_TO_USER_INFO,
				Notifications.MEDIATOR_APP_RESIZE
			
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			// TODO Auto Generated method stub
			super.handleNotification(notification);
			
			switch(notification.getName())
			{
				case Notifications.MEDIATOR_SWITCH_SCENE:
					var num:int = uiLayer.numChildren;
					var frame:Frame = null;
					for(var i:int=0;i<num;++i)
					{
						frame = uiLayer.getChildAt(i) as Frame;
						if(frame)
						{
							frame.reset();
						}
					}
					break;
				case Notifications.MEDIATOR_SWITCH_TO_USER_INFO:		//登录成功,切换至详细页面
					Tracker.log(Notifications.MEDIATOR_SWITCH_TO_USER_INFO);
					sendNotification(Notifications.MEDIATOR_TO_INIT_ACCESS_LIST);
					var accessFrame:FrameAccessList = (facade.retrieveMediator(MediatorAccessListFrame.NAME) as MediatorAccessListFrame).frame;
					var frameLogin:FrameLogin = (facade.retrieveMediator(MediatorLoginFrame.NAME) as MediatorLoginFrame).frame;
					UtilsAnimation.showLayoutAnimation1(frameLogin,accessFrame,function():void{
						sendNotification(Notifications.MEDIATOR_TO_SHOW_ACCESS_LIST);
					});
					break;
				case Notifications.MEDIATOR_APP_RESIZE:
					var num:int = uiLayer.numChildren;
					var frame:Frame = null;

					for(var i:int=0;i<num;++i)
					{
						frame = uiLayer.getChildAt(i) as Frame;
						if(frame)
						{
							frame.resize(null);
						}
					}
					LayoutManager.resizeHandler(null);
					break;
			}
		}
		
		
	}
}